package org.liaohailong.zxingdemo

import android.Manifest
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.google.zxing.client.android.CaptureActivity

class MainActivity : AppCompatActivity() {
    companion object {
        const val REQUEST_QR_SCAN = 10086
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val permissions = arrayOf(
            Manifest.permission.CAMERA,
            Manifest.permission.VIBRATE,
            Manifest.permission.READ_CONTACTS,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.CHANGE_WIFI_STATE,
            Manifest.permission.ACCESS_WIFI_STATE
        )
        ActivityCompat.requestPermissions(this, permissions, 0)

        findViewById<Button>(R.id.btn_qr_code).setOnClickListener {
            // open zxing QR code scan
            val intent = Intent(it.context, CaptureActivity::class.java)
            startActivityForResult(intent, REQUEST_QR_SCAN)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_QR_SCAN) {

            }
        }
    }
}